import Vue from 'vue'
import '../lib/jquery.slimscroll.min.js'
Vue.directive("hasChard", function (el) {
  if($(el).find("li").length<=0){
    $(el).remove()
  }
})
// single
/*Vue.directive("hasPermission", function (el, binding) {
  var permissions=JSON.parse(localStorage.getItem("permissions"));
  var admin=JSON.parse(localStorage.getItem("admin"));
  // console.log(el);
  // console.log(binding);
  if((permissions[binding.value]==undefined || !permissions) && !admin){
    var cur = $(el);
    // var parent = cur.parent("div");
    // console.log(el.parentNode);
    cur.css("display","none");
    cur.remove();
  }
})*/

Vue.directive("hasPermission", {
  bind:function (el, binding, vnode) {
    var permissions=JSON.parse(localStorage.getItem("permissions"));
    var admin=JSON.parse(localStorage.getItem("admin"));
    if((!permissions || !permissions[binding.value]) && !admin){
      vnode.componentInstance.$destroy();
      if($(el).attr("class") && $(el).attr("class").indexOf("el-menu-item")>-1){
        $(el).remove();
      }
      $(el).on("click",function(event){
        vnode.context.$message.error('您没有当前操作的权限!');
        return false;
      })
      if($(el).hasClass("btn-primary")){
        console.log(el);
        console.log("-----------6666666")
        $(el).addClass("btn-no-permission");
      }
      if(vnode.componentInstance.type=='text'){
        $(el).addClass("href-no-permission");
      }
      /*if(vnode.componentOptions.tag=='router-link'){
        $(el).addClass("a-no-permission");
        if ($(el).find(".el-button").hasClass("btn-primary")){
          $(el).find(".el-button").addClass("btn-no-permission");
        }
      }*/
    }
  }
});


/*

Vue.directive("hasPermission", {
  bind:function (el, binding, vnode) {
    var permissions=JSON.parse(localStorage.getItem("permissions"));
    // console.log("---------================");
    // console.log(el);
    // console.log( binding);
    // console.log( vnode);
    $(el).append("<span>111</span>")
    var admin=JSON.parse(localStorage.getItem("admin"));
    if((!permissions || !permissions[binding.value]) && !admin){
      var noPermissionInner = function(e){
        console.log("-2222");
      }
      var html=$(el).html();
      html="<span>"+html+"</span>";
      $("input").trigger("select");
      $(el).find("span").on("click",function(event){
        vnode.context.$message.error('您没有当前操作的权限!');
        //js阻止链接默认行为，没有停止冒泡
        console.log(event);
        alert("11111")
        event.preventDefault();
        //阻止事件冒泡
        event.cancelBubble = true;
        event.stopPropagation();
        return false;
      })
      // vnode.componentInstance.handleClick = noPermission;
      vnode.componentInstance.disabled = false;
      // vnode.componentInstance.handleInnerClick = noPermissionInner;
      if($(el).hasClass("btn-primary")){
        $(el).addClass("btn-no-permission");
      }
      if(vnode.componentInstance.type=='text'){
        $(el).addClass("href-no-permission");
      }

    }
  }
});
*/
